﻿Imports QLPhuTungOto.Data
Imports QLPhuTungOto.Bus
Public Class frmThemNhaCungCap

    Dim NCC_BUS As New NhaCungCapBUS

    Private Sub btnHuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        Close()
    End Sub

    Private Sub ThemNCC()
        Dim ncc As New NhaCungCap With {.TenNhaCungCap = txtTenNhaCungCap.Text,
                                        .Sdt = "",
                                        .Fax = "",
                                        .DiaChi = "",
                                        .ThongTinKhac = "",
                                        .IsDelete = 0}
        NCC_BUS.ThemNhaCungCap(ncc)
    End Sub

    Private Sub btnThemNhaCungCap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnThemNhaCungCap.Click

        If txtTenNhaCungCap.Text.Trim.Length <> 0 Then
            Try
                If NCC_BUS.LayNhaCungCapTheoTen(txtTenNhaCungCap.Text).TenNhaCungCap = txtTenNhaCungCap.Text Then
                    If MessageBox.Show("Tên nhà cung cấp đã tồn tại." + ControlChars.NewLine + "Bạn có muốn tiếp tục không?", "Câu hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
                        = DialogResult.Yes Then
                        ThemNCC()
                        TrangThai.ThayDoiNhaCungCap()
                        Close()
                    End If
                Else
                    ThemNCC()
                    TrangThai.ThayDoiNhaCungCap()
                    Close()
                End If
            Catch ex As Exception
                MessageBox.Show("Không thể thêm nhà cung cấp", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        End If

    End Sub
End Class